Skip to content

Conversation

@RulaKhaled
Copy link
Member

@RulaKhaled RulaKhaled commented Oct 13, 2025

Fixes: #17809

Implements message truncation logic that drops oldest messages first until the payload fits within the 20KB limit. If a single message exceeds the limit, its content is truncated from the end. Supports OpenAI/Anthropic ({ role, content }) and Google GenAI ({ role, parts: [{ text }] }) message formats.

cursor[bot]

This comment was marked as outdated.

@RulaKhaled RulaKhaled marked this pull request as draft October 13, 2025 14:56
@github-actions
Copy link
Contributor

github-actions bot commented Oct 13, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.63 kB - -
@sentry/browser - with treeshaking flags 23.11 kB - -
@sentry/browser (incl. Tracing) 40.97 kB - -
@sentry/browser (incl. Tracing, Profiling) 45.26 kB - -
@sentry/browser (incl. Tracing, Replay) 79.29 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.97 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 83.99 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.16 kB - -
@sentry/browser (incl. Feedback) 41.3 kB - -
@sentry/browser (incl. sendFeedback) 29.29 kB - -
@sentry/browser (incl. FeedbackAsync) 34.22 kB - -
@sentry/react 26.31 kB - -
@sentry/react (incl. Tracing) 42.97 kB - -
@sentry/vue 29.11 kB - -
@sentry/vue (incl. Tracing) 42.75 kB - -
@sentry/svelte 24.64 kB - -
CDN Bundle 26.9 kB - -
CDN Bundle (incl. Tracing) 41.62 kB - -
CDN Bundle (incl. Tracing, Replay) 77.87 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 83.35 kB - -
CDN Bundle - uncompressed 78.86 kB - -
CDN Bundle (incl. Tracing) - uncompressed 123.44 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 238.48 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 251.24 kB - -
@sentry/nextjs (client) 45.11 kB - -
@sentry/sveltekit (client) 41.4 kB - -
@sentry/node-core 50.75 kB - -
@sentry/node 154.93 kB +0.32% +493 B 🔺
@sentry/node - without tracing 92.61 kB -0.01% -1 B 🔽
@sentry/aws-serverless 106.33 kB -0.01% -1 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Oct 13, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,590 - 9,248 -7%
GET With Sentry 1,357 16% 1,398 -3%
GET With Sentry (error only) 6,079 71% 6,209 -2%
POST Baseline 1,204 - 1,194 +1%
POST With Sentry 501 42% 526 -5%
POST With Sentry (error only) 1,049 87% 1,067 -2%
MYSQL Baseline 3,277 - 3,344 -2%
MYSQL With Sentry 389 12% 495 -21%
MYSQL With Sentry (error only) 2,678 82% 2,752 -3%

View base workflow run

@RulaKhaled RulaKhaled marked this pull request as ready for review October 20, 2025 08:04
* Calculate the UTF-8 byte length of a string.
*/
const utf8Bytes = (text: string): number => {
return new TextEncoder().encode(text).length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: TextEncoder is not available in Bun Workers. I am not sure if this is something we want to support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I am officially confused: https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder. Anyways - I think it is safe to assume that Bun is listed and it will work

@RulaKhaled RulaKhaled requested a review from JPeer264 October 21, 2025 14:49
Copy link
Member

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RulaKhaled RulaKhaled merged commit 718a3ea into develop Oct 21, 2025
192 of 193 checks passed
@RulaKhaled RulaKhaled deleted the genai-msg-limit branch October 21, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Byte Size Limit and Oldest First Truncation for gen_ai.*.messages

2 participants